﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DAL;
using DAL.TWTZ;
using Models;

namespace BLL.TWTZ
{
    /// <summary>
    /// 体温台账
    /// </summary>
    public class TwtzBLL
    {
        private readonly TwtzDal _TwtzDAL;
        private readonly SqlDbHelper _SqlDbHelper;

        public TwtzBLL()
        {
            _TwtzDAL = new TwtzDal();
            _SqlDbHelper = new SqlDbHelper();
        }

        #region 新增及保存
        /// <summary>
        /// 新增及保存
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int SaveTwtz(TwtzModel entity)
        {
            try
            {
                return _TwtzDAL.SaveTwtz(entity);
            }
            catch (Exception)
            {

                throw;
            }
        }
        #endregion

        #region 删除单位对象
        /// <summary>
        /// 删除对象
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int RemoveTwtz(string id)
        {
            try
            {
                return _TwtzDAL.RemoveTwtz(id);
            }
            catch (Exception)
            {

                throw;
            }
        }
        #endregion

        #region 获取体温台账对象
        /// <summary>
        /// 获取体温台账对象
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public TwtzModel GetEntity(string id)
        {
            try
            {
                return _TwtzDAL.GetEntity(id);
            }
            catch (Exception)
            {

                throw;
            }
        }
        #endregion

        #region 获取体温台账对象的测温人员
        /// <summary>
        /// 获取体温台账对象的测温人员
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public List<TemperaturePerson> GetTemperaturePersonList(string id)
        {
            try
            {
                return _TwtzDAL.GetTemperaturePersonList(id);
            }
            catch (Exception)
            {

                throw;
            }
        }
        #endregion

        #region 获取当前节点下的子集合
        /// <summary>
        /// 获取当前节点下的子集合
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public List<TwtzModel> GetListByUnitId(string UnitId)
        {
            try
            {
                return _TwtzDAL.GetListByUnitId(UnitId);
            }
            catch (Exception)
            {
                throw;
            }
        }
        #endregion

        #region 获取所有体温台账信息
        /// <summary>
        /// 获取所有体温台账信息
        /// </summary>
        public List<TwtzModel> GetList()
        {
            try
            {
                return _TwtzDAL.GetList();
            }
            catch (Exception)
            {
                throw;
            }
        }
        #endregion

        #region 微信小程序获取测温列表
        public DataTable GetPageList(int pageSize,int pageIndex,string tableName,string fieldNames, string pkId, string strWhere,string sort,string sidx, out int total, out int records)
        {
            QueryCondition condition = new QueryCondition();
            condition.pageSize = pageSize;
            condition.pageIndex = pageIndex;
            condition.tableName = tableName;
            condition.fieldNames = fieldNames;
            condition.strWhere = strWhere;
            condition.sort = sort;
            condition.sidx = sidx;
            condition.pkId = pkId;
            DataTable dt = new DataTable();
            dt = _SqlDbHelper.GetPager(condition);
            total = condition.total.Value;
            records = condition.records.Value;
            return dt;
        }
        #endregion

        #region 根据单位获取测温人员
        public int GetTemperaturePersonList(string unitid, string persontype)
        {
            try
            {
                return _TwtzDAL.GetTemperaturePersonList(unitid, persontype);
            }
            catch (Exception)
            {

                throw;
            }
        }
        #endregion
    }
}
